package com.kaiwukj.android.ufamily.mvp.ui.page.service.gm;

import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.StringUtils;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.base.review.BaseActivity;
import com.kaiwukj.android.ufamily.app.constant.ARouterUrlKt;
import com.qmuiteam.qmui.widget.webview.QMUIWebView;
import com.qmuiteam.qmui.widget.webview.QMUIWebViewClient;

import butterknife.BindView;
import butterknife.OnClick;

@Route(path = ARouterUrlKt.GMFilePreviewUrl)
public class GMPreviewActivity extends BaseActivity {


    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.web)
    QMUIWebView webView;

    @Autowired
    String url = "";

    @OnClick(R.id.container_left)
    void onBackClick() {
        onBackPressedSupport();
    }

    @Override
    protected int getLayoutId() {
        ARouter.getInstance().inject(this);
        return R.layout.activity_web_base;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        if (StringUtils.isEmpty(url)) {
            showMessage("找不到文件");
            return;
        }

        webView.setWebViewClient(new QMUIWebViewClient(false, false) {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                // 防止加载网页时调起系统浏览器
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
                    view.loadUrl(url);
                    return true;
                }
                return false;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                showLoading("正在加载...");
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                hideLoading();
            }
        });

        webView.loadUrl(url);

    }

    @Override
    protected void initData(Bundle savedInstanceState) {

    }
}
